function energy(x, y, width, height, type, speed, kind) {
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	this.type = type;
	this.speed = speed;
	this.isGet = false;
	//种类
	this.kind = kind;
	this.img = new Image;
	this.img.src = "img/" + type + ".png";
}

function fnRand(max, min) {
	return parseInt(Math.random() * (max - min + 1) + min);
}

function energyClass(energyball) {
	this.energyArray = [];
	this.creatEnergy = function() {
		var num = fnRand(1,10000);
		//类型1
		if(num > 20 && num < 25) {
			var energy1 = new energy(fnRand(0, canvas.width - 150), -164, 40, 67, "prop", fnRand(1, 5), 2);
			// 保证能力包一次性出现不超过俩个
			if (this.energyArray.length < 2) {
				this.energyArray.push(energy1);
			}
			
		}
		//类型2
		if(num >30 && num < 35) {
			var energy2 = new energy(fnRand(0, canvas.width - 150), -164, 40, 67, "prop", fnRand(2, 3), 0);
			if (this.energyArray.length < 2) {
				this.energyArray.push(energy2);
			}
			
		}
		//类型3
		if(num >14 && num < 18) {
			var energy3 = new energy(fnRand(0, canvas.width - 150), -164, 40, 67, "prop", fnRand(1, 4), 1);
			if (this.energyArray.length < 2) {
				this.energyArray.push(energy3);
			}
			
		}
		//移动
		for(var i = 0; i < this.energyArray.length; i++) {
			if(this.energyArray[i].y > canvas.height) {
				this.energyArray.splice(i, 1);
				continue;
			}
			if(this.energyArray[i].isGet) {
				this.energyArray.splice(i, 1);
				continue;
			} else {
				this.energyArray[i].y += this.energyArray[i].speed;
			}

			context.beginPath();
			context.drawImage(this.energyArray[i].img, this.energyArray[i].width * this.energyArray[i].kind, 0, this.energyArray[i].width, this.energyArray[i].height, this.energyArray[i].x, this.energyArray[i].y, this.energyArray[i].width, this.energyArray[i].height);
			context.save();
		}
	}
}